package com.xjtu.chapter07.ex7_3;

import javax.swing.*;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/19 9:55
 */

public class Menu extends JFrame {
    JMenuBar menubar;   //菜单条
    JMenu menuFile; //菜单
    JMenuItem itemNew, itemReset,itemExit;   //菜单项

    public Menu() {
    }

    public Menu(String string) {
        init(string);
        setVisible(true);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    void init(String s) {
        setTitle(s);
        menubar = new JMenuBar();
        menuFile = new JMenu("File");
        itemNew = new JMenuItem("New Game");
        itemReset = new JMenuItem("Reset Game");
        itemExit = new JMenuItem("Exit");

        menubar.add(menuFile);  //将菜单添加到菜单条上
        menuFile.add(itemNew);
        menuFile.add(itemReset);
        menuFile.add(itemExit);
        setJMenuBar(menubar);
    }
}

